import requests

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'http://59.215.206.188',
    'Referer': 'http://59.215.206.188/zhslzy/accept/monitor/allbusiness/index',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'Cookie': 'JSESSIONID=DC76220CD758F8A69AB7C42E5FFA2763; wyhijack=/login/js/chunk-9e9c9b90.1027afce.js_1758675914078; James_cookie_sYQDUGqqzHtheme=custom; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6Imh0dHA6Ly81OS4yMTUuMjA2LjE4OC9sb2dpbi8iLCJyb2xlIjoiUk9MRV9BUkVBLFJPTEVfV0lORE9XIiwiaXNJbml0aWFsUGFzc3dvcmQiOiIwIiwicmVnaW9uTmFtZSI6Iui0teW3nuecgSIsImluZHVzdHJ5IjpudWxsLCJhcHBDb2RlIjoiZGdvdi1wb3J0YWwiLCJvcmdhbk5hbWUiOiLmlrDov5vkurrlkZgiLCJyZWdpb25Db2RlIjoiNTIwMDAwIiwiaW5kdXN0cnlMaXN0IjpudWxsLCJvcmdhbkNvZGUiOiI1MjAwMDAyMDE3MDIxNjEwMDUzMDAwMDUwNyIsImV4cGlyYXRpb25UaW1lIjoxNCwiZ3JhZGUiOiIyIiwic3RhdHVzIjoiMSIsImlzcyI6Imluc3B1ciIsImlhdCI6MTc2MTAwODU5MywiZXhwIjoxNzYxMDM3MzkzfQ.svWI6ZIxusZY1H3eDBRf89GqmQno-jgKWK7YE2XXGLC6Q-SYmVcUWJmYdAxg4qLC3XBFFql-8JwcNlmtnMReew; userInfoKey={%22role%22:%22ROLE_AREA%2CROLE_WINDOW%22%2C%22isInitialPassword%22:%220%22%2C%22regionName%22:%22%E8%B4%B5%E5%B7%9E%E7%9C%81%22%2C%22appCode%22:%22dgov-portal%22%2C%22organName%22:%22%E6%96%B0%E8%BF%9B%E4%BA%BA%E5%91%98%22%2C%22regionCode%22:%22520000%22%2C%22phone%22:%22384d53fa06a4844cfd54260b048c33e9%22%2C%22organCode%22:%2252000020170216100530000507%22%2C%22expirationTime%22:14%2C%22name%22:%221342b48e6f8f39ea7ba36accc05b61a8%22%2C%22id%22:%229E1059C9335D4C7CB8DC7400D03AECFB%22%2C%22email%22:%223f9980534589201ab2c5f2481db36392%22%2C%22username%22:%2247d57692a252657367001b6a2ff35333%22%2C%22status%22:%221%22%2C%22isWeakPwd%22:%220%22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4; webfinal.session.errorCount=0; tempTokenKey-slsp=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6Imh0dHA6Ly81OS4yMTUuMjA2LjE4OC9oYW5kbGUtYnVzaW5lc3MtdWkvIiwicm9sZSI6IkNKWVlfU1lTVEVNLENKWVlfQlVTSU5FU1NfREVsRVRFLENKWVlfQlVTSU5FU1NfREVsRVRFX0VYQU1JTkUsQ0pZWV9CVVNJTkVTUyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6IkRHT1YtWldGVy1TTFNQIiwib3JnYW5OYW1lIjoi5paw6L-b5Lq65ZGYIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAwMjAxNzAyMTYxMDA1MzAwMDA1MDciLCJleHBpcmF0aW9uVGltZSI6MTQsImdyYWRlIjoiMiIsInN0YXR1cyI6IjEiLCJpc3MiOiJpbnNwdXIiLCJpYXQiOjE3NjEwMTU1MDQsImV4cCI6MTc2MTA0NDMwNH0.v8UNkbIK_DgPWlmgnQDk3NgFECZdcdlOgPjsJtb58PXhVTAxYa-hOJ4t7L_klqZVTqRAx-pA-HlCTHrCulPxBg; userInfoKey-slsp={%22role%22:%22CJYY_SYSTEM%2CCJYY_BUSINESS_DElETE%2CCJYY_BUSINESS_DElETE_EXAMINE%2CCJYY_BUSINESS%22%2C%22isInitialPassword%22:%220%22%2C%22regionName%22:%22%E8%B4%B5%E5%B7%9E%E7%9C%81%22%2C%22appCode%22:%22DGOV-ZWFW-SLSP%22%2C%22organName%22:%22%E6%96%B0%E8%BF%9B%E4%BA%BA%E5%91%98%22%2C%22regionCode%22:%22520000%22%2C%22phone%22:%2218198171062%22%2C%22organCode%22:%2252000020170216100530000507%22%2C%22expirationTime%22:14%2C%22name%22:%22%E7%86%8A%E6%AF%85%22%2C%22id%22:%229E1059C9335D4C7CB8DC7400D03AECFB%22%2C%22email%22:%22123@qq.com%22%2C%22username%22:%22gys_xy%22%2C%22status%22:%221%22%2C%22windowId%22:%2211EF7D785488E5FCBAD4AF91FADA434E%22%2C%22windowName%22:%22%E9%81%B5%E4%B9%89%E5%B8%82%E4%B8%80%E4%BB%B6%E4%BA%8B%E7%AA%97%E5%8F%A3%22%2C%22windowCode%22:%22%E9%81%B5%E4%B9%89%E5%B8%82%E4%B8%80%E4%BB%B6%E4%BA%8B%E7%AA%97%E5%8F%A3%22%2C%22hallName%22:%22%E9%81%B5%E4%B9%89%E5%B8%82%E6%94%BF%E5%8A%A1%E6%9C%8D%E5%8A%A1%E4%B8%AD%E5%BF%83%22%2C%22hallCode%22:%2200001%22%2C%22windowRegionCode%22:%22520300%22%2C%22signAuthCode%22:%2252030000017129%22}',
}

lists={
  "遵义市医疗保障局": "520300w2345678",
  "遵义市红花岗区医保服务中心": "52030281",
  "遵义市汇川区医疗保障局": "5203032019051301",
  "遵义市播州区医疗保障局": "520321111589",
  "桐梓县医疗保障局": "52032211520322MB1561264W",
  "绥阳县医疗保障局": "11520323MB1988196B",
  "正安县医疗保障局": "11520324MB197259XL",
  "道真仡佬族苗族自治县医疗保障局": "52032511",
  "务川仡佬族苗族自治县医疗保障局": "520326952628701",
  "凤冈县医疗保障局": "52032700G",
  "湄潭县医疗保障局": "520328mtxybj",
  "余庆县医疗保障局": "70766303701",
  "习水县医疗保障局": "52033056789",
  "赤水市医疗保障局": "52038100000000001",
  "仁怀市医疗保障局": "MB1770939K",
  "遵义市新蒲新区管理委员会医疗保障局": "123125"
}
for k,v in lists.items():
    url = "http://59.215.206.188/zhslzy/accept/monitor/allbusiness/queryAllExportExcel?itemname=&start=&end=&bjstart=&bjend=&applynum=&applySubject=&applicant=&curState=&itemType=&state=&haslicense=&from=&regionCode=&orgCode={}&applyFrom=&isFastSearch=false&acceptUser=&assort=&serviceObject=&sidx=FINISH_TIME%20DESC,%20RECEIVE_TIME%20&sord=desc&receiveUser=&receiveTime_start=2025-01-01&receiveTime_end=2025-10-21&jumpState=&queryDepartment=0&isFinish=2&companyRegisterRegion=".format(v)
    res = requests.get(url, headers=headers)
    with open(f"{k}.xls", "wb") as f:
        for chunk in res.iter_content(chunk_size=10024):
            if chunk:
                f.write(chunk)
    print(f"xlsx文件已成功保存为 {k}.xls")